<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>清单应用Vue版</title>
  <!-- <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/3.2.31/vue.global.min.js"></script> -->
  <script src="./libs/vue.global.min.js"></script>
  <style>
    .done {
      text-decoration: line-through;
    }
  </style>
</head>

<body>
  <div id="app">
    <h2>{{title}}</h2>
    <input type="text" v-model="newItem">
    <button @click="addItem">添加</button>
    <ul>
      <li v-for="(item, index) in items" :key="index" @click="toggleDone(item)">
        <span :class="{'done': item.done}">{{ item.text }}</span>
      </li>
    </ul>
    <div>
      {{ items.filter(v =>!v.done).length}} / {{ items.length }}
    </div>
  </div>

  <script>
    const app = Vue.createApp({
      data() {
        return {
          title: '清单应用Vue版',
          newItem: '',
          items: [
            { text: '学习Vue', done: false },
            { text: '学习JavaScript', done: true },
          ]
        }
      },
      methods: {
        addItem() {
          if (this.title.trim() !== '') {
            this.items.push({ text: this.newItem, done: false })
            this.newItem = ''
          }
        },
        toggleDone(item) {
          item.done = !item.done
        }
      }
    }).mount('#app')
  </script>
</body>

</html>